package com.weetop.aklyscan.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonRecyclerAdapter;
import com.weetop.aklyscan.R;
import com.weetop.aklyscan.base.BaseActivity;
import com.weetop.aklyscan.base.mvp.BaseModel;
import com.weetop.aklyscan.bean.RecordListBean;
import com.weetop.aklyscan.presenter.RecordPresent;
import com.weetop.aklyscan.view.RecordView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ZXRecordListActivity extends BaseActivity<RecordPresent> implements RecordView, CommonRecyclerAdapter.OnItemClickListener {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.tv_huojia)
    TextView tv_huojia;
    @BindView(R.id.txt_title)
    TextView txt_title;
    @BindView(R.id.tv_time)
    TextView tv_time;
    @BindView(R.id.tv_num)
    TextView tv_num;
    @BindView(R.id.tv_num_1)
    TextView tv_num_1;
    @BindView(R.id.tv_type)
    TextView tv_type;
    @BindView(R.id.ll1)
    View typeLayoutView;
    @BindView(R.id.number)
    TextView number;
    private CommonRecyclerAdapter<RecordListBean> adapter;
    private List<RecordListBean> list = new ArrayList<>();
    private String order_type, order_sn;

    @Override
    protected RecordPresent createPresenter() {
        return new RecordPresent(this, this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_in_record_list);
        ButterKnife.bind(this);
        order_sn = getIntent().getStringExtra("order_sn");
        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        adapter = new CommonRecyclerAdapter<RecordListBean>(mActivity, R.layout.item_record_list_1, list) {
            @Override
            public void onUpdate(BaseAdapterHelper helper, RecordListBean item, int position) {
                helper.setText(R.id.tv_xuhao, position + 1 + "");
                helper.setText(R.id.tv_num, item.getTotal_num());
                helper.setText(R.id.tv_time, item.getCreate_time());
                helper.setText(R.id.tv_num_1, order_sn);
                helper.setText(R.id.tv_huojia, item.getApply_user_name());
            }
        };
        tv_huojia.setText("人员编号");
        txt_title.setText("装箱记录");
        tv_time.setText("装箱时间");
        tv_num.setText("装箱数量");
        tv_num_1.setText("凭证编号");
        tv_type.setText("装箱凭证类型");
//        tv_type.setVisibility(View.GONE);
        typeLayoutView.setVisibility(View.GONE);
        adapter.setOnItemClickListener(this);
        recyclerView.setAdapter(adapter);
        mPresenter.Into34(order_sn);
    }

    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void onItemClick(RecyclerView.ViewHolder viewHolder, View view, int i) {
        Intent intent = new Intent(ZXRecordListActivity.this, ZXRecordActivity.class);
        intent.putExtra("order_sn", order_sn);
        intent.putExtra("time", list.get(i).getCreate_time());
        startActivity(intent);
    }

    @Override
    public void getInto34Success(BaseModel<List<RecordListBean>> o) {
        List<RecordListBean> listBeans = o.getData();
        list.clear();
        adapter.clear();
        list.addAll(listBeans);
        adapter.addAll(listBeans);
        int count = 0;
        for(RecordListBean bean :o.getData()){
            count+=Integer.parseInt(bean.getTotal_num());
        }
        number.setText(count+"");
    }

}
